<?php 

namespace app\common\model\Subject\Teacher;

use think\Model;

// 教师模型
class Teacher extends Model
{
    protected $name = 'subject_teacher';
    protected $autoWriteTimestamp = true;
    protected $createTime = 'createtime';

    protected $updateTime = false;

    protected $append = [
        'avatar_text', // 头像
        'subject_text', // 教师教学课程数量
        'follow_text' // 粉丝数量
    ];

    public function getAvatarTextAttr($value, $data) {
        $avatar = !empty($data['avatar']) ? $data['avatar'] : '/assets/img/avatar.jpg';

        return $avatar;
    }

    public function getSubjectTextAttr($value, $data) {
        $count = model('Subject.Subject')->where('teacherid', $data['id'])->count();

        return $count;
    }

    public function getFollowTextAttr($value, $data) {
        $count = model('Subject.Teacher.Follow')->where('teacherid', $data['id'])->count();

        return $count;
    }
}

?>